package com.example.consumer.controller;

import com.example.consumer.feign.UserFeignClient;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create by jian.pan on 2018/6/19
 */
@RestController()
@RequestMapping("userController")
public class UserController {

  Logger logger = LoggerFactory.getLogger(UserController.class);

  @Autowired
  private AmqpTemplate amqpTemplate;

  @Autowired
  private UserService userService;

  @GetMapping("")
  public String getUser(){
    Method method = UserFeignClient.class.getMethods()[0];
    Annotation[] annotations = method.getAnnotations();
    System.out.println("length:"+annotations.length);
    if(annotations.length>0){

      System.out.println(annotations[0].getClass().getSimpleName());
      if(annotations.length>1) {
        System.out.println(annotations[1].getClass().getSimpleName());
      }
    }
    return userService.getUser();
  }

  @PostMapping("")
  public String send(){
    logger.info("send....");
    amqpTemplate.convertAndSend("send.............");
    return "ok";
  }
}
